package com.epoint.mvc.index;

import com.epoint.mybatis.domain.Inspection;
import com.epoint.mybatis.mapper.InspectionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Controller
public class IndexController {

    @Autowired
    private SpringTestBean springTestBean;

    @Autowired
    private InspectionMapper inspectionMapper;

    @GetMapping("/index")
    public String indexHtml(){
        return "index";
    }

    @GetMapping("/index2")
    public String indexHtml2(){
        return "index2";
    }

    @GetMapping("/index3/{id}/{name}")
    @ResponseBody
    public String indexHtml2(@PathVariable("id")String id, @PathVariable("name")String name){

        Inspection inspection = inspectionMapper.selectByPrimaryKey(id);
        System.out.println(inspection);

        System.out.println(id);
        System.out.println(name);
        return "JKH";
    }

    /**
     * url后面的参数 的获取方式
     * @param name
     * @param age
     * @return
     */
    @GetMapping("/param1")
    @ResponseBody
    public String param1(String name, int age){
        System.out.println(name);
        System.out.println(age);
        return "JKH";
    }

    @PostMapping("/testRequestParams")
    @ResponseBody
    public String testRequestParams(@RequestParam("params")String params){
        System.out.println(params);
        return "JKH";
    }


//    @GetMapping("/testIndex1")
//    public String testIndex1(){
//        return "redirect:/testIndex2";
//    }
//
//    @GetMapping("/testIndex2")
//    public String testIndex2(){
//        return "index2";
//    }
}
